package com.config;

import org.apache.shiro.realm.Realm;
import org.apache.shiro.realm.text.TextConfigurationRealm;
import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 */
@Configuration
public class ShiroConfig {
	
	/*****
	 * 配置用户 角色
	 * @return
	 */
    @Bean
    Realm realm() {
    	System.out.println("realm.................");
        TextConfigurationRealm realm = new TextConfigurationRealm();//相当于在内存中设置
        realm.setUserDefinitions("javaboy=123,user \n admin=123,admin");//设置用户  角色  
        realm.setRoleDefinitions("admin=read,write \n user=read");//设置权限
        return realm;
    }
    
    /***
     * 配置拦截规则
     * @return
     */
    @Bean
    ShiroFilterChainDefinition shiroFilterChainDefinition() {
    	System.out.println("shiroFilterChainDefinition");
        DefaultShiroFilterChainDefinition definition = new DefaultShiroFilterChainDefinition();
        definition.addPathDefinition("/doLogin", "anon");
        definition.addPathDefinition("/**", "authc");
        return definition;
    }
}
